package com.project.pulsar.conf;

import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PulsarConf {
    @Value("${pulsar.url}")
    String url;
    @Value("${pulsar.serviceHttpUrl}")
    String serviceHttpUrl;

    @Bean
    public PulsarClient pulsarFactory(){
        PulsarClient client = null;
        try {
            client = PulsarClient.builder()
                    .serviceUrl("pulsar://"+url)
                    .build();
        } catch (PulsarClientException e) {
            e.printStackTrace();
        }
        return client;
    }
    @Bean
    public PulsarAdmin pulsarAdminFactory(){
        PulsarAdmin admin =null;
        try {
            admin = PulsarAdmin.builder()
                    .serviceHttpUrl(serviceHttpUrl)
                    .build();
        } catch (PulsarClientException e) {
            e.printStackTrace();
        }
        return  admin;
    }
}
